package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Problem;
import cn.wolfcode.luowowo.article.domain.ProblemContent;
import cn.wolfcode.luowowo.article.mapper.ProblemContentMapper;
import cn.wolfcode.luowowo.article.mapper.ProblemMapper;
import cn.wolfcode.luowowo.article.service.IProblemService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * Created by Windows on 2020/1/11.
 */
@Service
public class ProblemServiceImpl implements IProblemService {

    @Autowired
    private ProblemMapper problemMapper;

    @Autowired
    private ProblemContentMapper problemContentMapper;

    @Override
    public List<Problem> list() {
        List<Problem> list = problemMapper.selectList();
        return list;
    }

    @Override
    public void save(Problem problem) {
        //添加问题
        problem.setDate(new Date());
        problemMapper.insert(problem);
        //添加问题内容
        problem.getTravelContent().setId(problem.getId());
        problemContentMapper.insert(problem.getTravelContent());

    }

    @Override
    public Problem getById(Long id) {
        //问题
        Problem problem = problemMapper.selectByPrimaryKey(id);
        //问题内容
        ProblemContent problemContent = problemContentMapper.selectByPrimaryKey(id);
        problem.setTravelContent(problemContent);
        return problem;
    }
}
